*** REPEATEDLY LOSING ***STATA/MP 18.0
clear
set more off

import delimited "C:\Users\u126910\Downloads\raw_data_repeatedly_losing.csv", bindquote(strict) varnames(1)
browse
browse,nolab
drop in 1
* dropping the uncompleted surveys. v10 is 1 for completion and 0 noncompletion. 
* but it needs to be destringed
encode v10,gen(completion)
tab completion, nolab
drop if completion==1 
//218 observations were deleted. 

* to delete the speaders

*** TO EXTRACT THE DATE AND TIME ***
***Extract starting and completion time
gen double starttime=clock(substr(v8, 12, 12), "hms")
format starttime %tcHH:MM:SS
 
gen double endtime=clock(substr(v9, 12, 12), "hms")
format endtime %tcHH:MM:SS
 
***Generate variables indicating time spent completing the survey
gen timespent=endtime-starttime       //time spent in miliseconds
gen timespent_seconds=timespent/1000  //time spent in seconds
gen timespent_minutes=timespent_seconds/60 //time spent in minutes

drop if timespent_seconds<300

duplicates list psid

* there is one psid duplicated, so I delete the next one. 
drop in 1570

destring,replace

* Rename variables *
tab q2
gen gender=.
replace gender=0 if q2==2 // men
replace gender=1 if q2==1 // women
tab q2 gender
sum gender

tab q3
gen age=2019-q3 //age
sum age
replace age=. if age==99 | age==119 // remove unrealistic age

tab q4_1, m
gen trustparl_pre=q4_1 // trust in parliament

tab q4_2, m
gen trustgov_pre=q4_2 // trust in government

tab q4_3, m
gen trustpoli_pre=q4_3 // trust in politicians

tab q4_4, m
gen trustparty_pre=q4_4 // trust in political parties


**


tab q5_1, m
gen swd_pre=q5_1 // satisfaction with democracy in Ireland
sum swd_pre

tab q6_1, m
gen willvoteref_pre=q6_1 // willingness to vote in a referendum

tab q7_1, m
gen leftright=q7_1 // left-right placement (0=left; 10=right)

tab q8, m
tab q8, m nolab
gen polintr= q8 // interest in politics

tab q9_2, m
tab q9_2, m nolab
recode q9_2 (6=99) 			// recode "don't know" --> 99
gen issuesal_divorce= q9_2 // issue salience divorce time

tab q9_10 , m
tab q9_10, m nolab
recode q9_10 (6=99) // recode "don't know" --> 99
gen issuesal_baincome= q9_10 // issue salience basic income

tab q9_11 , m
tab q9_11, m nolab
recode q9_11 (6=99) // recode "don't know" --> 99
gen issuesal_womenrole= q9_11 // issue salience women's role in the home

tab q9_12, m
tab q9_12, m nolab
recode q9_12 (6=99) // recode "don't know" --> 99
gen issuesal_votingage = q9_12 // issue salience voting age

tab q9_13, m
tab q9_13, m nolab
recode q9_13 (6=99) // recode "don't know" --> 99
gen issuesal_directelect = q9_13 // issue salience direct election of mayors


*

*
tab q10, m
tab q10, m nolab
gen partyid= . // gen party id variable
replace partyid= 0 if q10==2
replace partyid= 1 if q10==1
sum partyid

tab q11, m
gen partyid_party= q11 // party id for which party?

tab q12_1 
tab q12_1, m nolab
tab q12_4 
tab q12_4, m nolab
tab q12_5 
tab q12_5, m nolab
tab q12_6 
tab q12_6, m nolab
tab q12_7 
tab q12_7, m nolab
recode q12_1 q12_4 q12_5 q12_6 q12_7 (5=8)  //correct strange coding
recode q12_1 q12_4 q12_5 q12_6 q12_7(10=5) 
recode q12_1 q12_4 q12_5 q12_6 q12_7 (11=6) 
recode q12_1 q12_4 q12_5 q12_6 q12_7 (12=7) 

gen tv= q12_1
gen newspaper= q12_4
gen radionews= q12_5
gen socialmedia= q12_6
gen internetnews= q12_7

tab q17
tab q17, m nolab
gen decision1=. // vote choice on the first decision (women's life in the home)
replace decision1=0 if q17==2 // not approve removing references
replace decision1=1 if q17==1 // approve removing references
sum decision1

graph bar, over(decision1)


tab q20
tab q20, m nolab
gen decision2=. // vote choice on the second decision (reduce waiting time for divorce)
replace decision2=0 if q20==2 // not approve reducing waiting time
replace decision2=1 if q20==1 // approve reducing waiting time
sum decision2

graph bar, over(decision2)

tab q23
tab q23, m nolab
gen decision3=. // vote choice on the third decision (reduce voting age)
replace decision3=0 if q23==2
replace decision3=1 if q23==1
sum decision3

graph bar, over(decision3)


gen group=. // variable that indicates the treatment group
replace group= 1 if www4_1!=. // WWW condition
replace group= 2 if wwl4_1!=. // WWL condition
replace group= 3 if wlw4_1!=. // WLW condition
replace group= 4 if wll4_1!=. // WLL condition
replace group= 5 if lww4_1!=. // LWW condition
replace group= 6 if lwl4_1!=. // LWL condition
replace group= 7 if llw4_1!=. // LLW condition
replace group= 8 if lll4_1!=. // LLL condition

lab define group 1"WWW" 2"WWL" 3"WLW" 4"WLL" 5"LWW" 6"LWL" 7"LLW" 8"LLL"


gen accept1=. // acceptance of the first decision
replace accept1= www4_1 if group==1
replace accept1= wwl4_1 if group==2
replace accept1= wlw4_1 if group==3
replace accept1= wll4_1 if group==4
replace accept1= lww4_1 if group==5
replace accept1= lwl4_1 if group==6
replace accept1= llw4_1 if group==7
replace accept1= lll4_1 if group== 8
sum accept1 
sum accept1 if group<=4 // average for winners
sum accept1 if group>4 // average for losers

gen accept2=. // acceptance of the second decision
replace accept2= www8_1 if group==1
replace accept2= wwl8_1 if group==2
replace accept2= wlw8_1 if group==3
replace accept2= wll8_1 if group==4
replace accept2= lww8_1 if group==5
replace accept2= lwl8_1 if group==6
replace accept2= llw8_1 if group==7
replace accept2= lll8_1 if group== 8
sum accept2 
sum accept2 if group==1 | group==2 | group==5 | group==6 // average for winners
sum accept2 if group==3 | group==4 | group==7 | group==8 // average for losers


gen accept3=. // acceptance of the third decision
replace accept3= www12_1 if group==1
replace accept3= wwl12_1 if group==2
replace accept3= wlw12_1 if group==3
replace accept3= wll12_1 if group==4
replace accept3= lww12_1 if group==5
replace accept3= lwl12_1 if group==6
replace accept3= llw12_1 if group==7
replace accept3= lll12_1 if group==8
sum accept3 
sum accept3 if group==1 | group==3 | group==5 | group==7 // average for winners
sum accept3 if group==2 | group==4 | group==6 | group==8 // average for losers


factor q24_3 q24_4 q24_5 q24_6 q24_8 q24_10 q24_13 q24_17

rotate, promax

tab q25_1
tab q25_1, nolab m
gen satisref= q25_1 // statisfaction with the referendum 


// emotions
recode q24_3 (5=1)(4=2)(3=3)(2=4)(1=5),gen(alarmed) // now it ranges from 1- not at all, to 5- extremely
tab alarmed
tab q24_3
drop q24_3
lab var alarmed alarmed

recode q24_4 (5=1)(4=2)(3=3)(2=4)(1=5),gen(hopeful) // now it ranges from 1- not at all, to 5- extremely
tab hopeful
tab q24_4
drop q24_4
lab var hopeful hopeful

recode q24_5 (5=1)(4=2)(3=3)(2=4)(1=5),gen(angry) // now it ranges from 1- not at all, to 5- extremely
tab angry
tab q24_5
drop q24_5
lab var angry angry

recode q24_6 (5=1)(4=2)(3=3)(2=4)(1=5),gen(frustrated) // now it ranges from 1- not at all, to 5- extremely
tab frustrated
tab q24_6
drop q24_6
lab var frustrated frustrated

recode q24_8 (5=1)(4=2)(3=3)(2=4)(1=5),gen(proud) // now it ranges from 1- not at all, to 5- extremely
tab proud
tab q24_8
drop q24_8 
lab var proud proud

recode q24_10 (5=1)(4=2)(3=3)(2=4)(1=5),gen(excited) // now it ranges from 1- not at all, to 5- extremely
tab excited
tab q24_10
drop q24_10
lab var excited excited 

recode q24_13 (5=1)(4=2)(3=3)(2=4)(1=5),gen(happy) // now it ranges from 1- not at all, to 5- extremely
tab happy
tab q24_13
drop q24_13
lab var happy happy


recode q24_17 (5=1)(4=2)(3=3)(2=4)(1=5),gen(outraged) // now it ranges from 1- not at all, to 5- extremely
tab outraged
tab q24_17
drop q24_17
lab var outraged outraged

///q26_1, the process was fair 

rename q26_1 fair_process
lab var fair_process process_was_fair

rename q26_2 moral_expect 
lab var moral_expect process_fulfills_moral_expect

rename q26_3 influence_dec 
lab var influence_dec influence_dec

rename q26_4 state_opinion
lab var state_opinion state_opinion

**

factor fair_process moral_expect influence_dec state_opinion
// procedural fairness as a latent factor?

gen pros=(fair_process+moral_expect+influence_dec+state_opinion) 

// procedural fairness perceptions

tab q27
gen reasonunfair= q27 // reasons why process was unfair (open question)

tab q28
gen reasonfair = q28 // reasons why process was fair (open question) 


tab q29_1, m
gen trustparl_post=q29_1 // trust in parliament

tab q29_2, m
gen trustgov_post=q29_2 // trust in government

tab q29_3, m
gen trustpoli_post=q29_3 // trust in politicians

tab q29_4, m
gen trustparty_post=q29_4 // trust in political parties

sum trustparl_post trustgov_post trustpoli_post trustparty_post

graph bar (mean) trustparl_post (mean) trustgov_post (mean) trustpoli_post (mean) trustparty_post


sum trustparl_pre trustparl_post
sum trustgov_pre trustgov_post
sum trustpoli_pre trustpoli_post
sum trustparty_pre trustparty_post

tab q30_1, m
gen swd_post=q30_1 // satisfaction with democracy in Ireland
sum swd_pre swd_post

tab q31_1, m
gen willvoteref_post=q31_1 // willingness to vote in a referendum
sum willvoteref_pre willvoteref_post

tab q32
tab q32, nolab m
gen changeprocedure= q32 // opinion on whether process needs to be changed

tab q33
gen reasonschangeprocedure= q33

tab q34
gen MC1=. // first manipulation check
replace MC1=1 if q34==1 & group==8 // never consistent
replace MC1=0 if q34==1 & group<8

replace MC1=1 if q34==2 & group==4 // once consistent
replace MC1=1 if q34==2 & group==6
replace MC1=1 if q34==2 & group==7
replace MC1=0 if q34==2 & group==1
replace MC1=0 if q34==2 & group==2
replace MC1=0 if q34==2 & group==3
replace MC1=0 if q34==2 & group==5
replace MC1=0 if q34==2 & group==8

replace MC1=1 if q34==3 & group==2 // twice consistent
replace MC1=1 if q34==3 & group==3
replace MC1=1 if q34==3 & group==5
replace MC1=0 if q34==3 & group==1
replace MC1=0 if q34==3 & group==4
replace MC1=0 if q34==3 & group==6
replace MC1=0 if q34==3 & group==7
replace MC1=0 if q34==3 & group==8

replace MC1=1 if q34==4 & group==1 // three times consistent
replace MC1=0 if q34==4 & group>1 

replace MC1=0 if q34==5 // respondents who did not recall

sum MC1
tab MC1

tab q35
tab q35, nolab m
gen MC2=. // second manipulation check
replace MC2=1 if q35==3
replace MC2=0 if q35<3
replace MC2=0 if q35>3
sum MC2
tab MC2

tab q36
tab q36, nolab m
gen edu=q36

tab q37
tab q37, nolab m
gen class1=q37 // do you ever think of yourself belonging in one of these classes? yes,no, don't know (0, 1,99)


tab q38
tab q38, nolab m
gen class2=q38  // which one: lower class, or poor; middle class, working class, upper class, other (please specify) (1 2 3 4 5)


tab q40
gen comments=q40

alpha alarmed angry frustrated outraged // --> frustration

gen frustration=(alarmed+angry+frustrated+outraged) //alarmed, angry, frustrated ,outgraged


*****

lab var pros process_preferences_index

lab var gender gender
lab var age age
lab var trustparl_pre trustparl_pre
lab var trustgov_pre trustgov_pre
lab var trustpoli_pre trustpoli_pre
lab var trustparty_pre trustparty_pre
lab var swd_pre swd_pre
lab var willvoteref_pre willvoteref_pre
lab var leftright ideology
lab var polintr political_interest
lab var issuesal_divorce divorce_salience
lab var issuesal_baincome uni_salience
lab var issuesal_womenrole womenrole_salience
lab var issuesal_votingage voting_salience
lab var issuesal_directelect direct_elect_salience
lab var partyid partisanship
lab var partyid_party partisanship_2
lab var tv tv_consumption
lab var newspaper news_consumption
lab var radionews radio_consumption
lab var socialmedia socialmedia
lab var internetnews internet_news
lab var decision1 decision1
lab var decision2 decision2
lab var decision3 decision3
lab var group treatment_group
lab var accept1 accept1
lab var accept2 accept2
lab var accept3 accept3
lab var satisref satisref
lab var reasonunfair reasonunfair
lab var reasonfair reasonfair
lab var trustparl_post trustparl_post
lab var trustgov_post trustgov_post
lab var trustpoli_post trustpoli_post
lab var trustparty_post trustparty_post
lab var swd_post swd_post
lab var willvoteref_post willvoteref_post
lab var changeprocedure changeprocedure
lab var reasonschangeprocedure reasonschangeprocedure
lab var MC1 manipulation_check_1
lab var MC2 manipulation_check_2
lab var edu education
lab var class1 class1
lab var class2 class2
lab var comments comments
lab var frustration frustration
lab var pros process_preferences_index


drop v1 locationlatitude locationlongitude locationaccuracy completion
drop v2 v3 v4 v5 v6 v7 v8 v9 v10 psid q1 q2 q2_text q3 q4_1 q4_2 q4_3 q4_4 q5_1 q6_1 q7_1 q8 q9_2 q9_10 q9_11 q9_12 q9_13 q10 q11 q11_text q12_1 q12_4 q12_5 q12_6 q12_7 q13 q14 q141 q15 q16 q18 q19 q21 q22 www1 www2 www3 www4_1 www5 www6 www7 www8_1 www9 www10 www11 www12_1 wwl1 wwl2 wwl3 wwl4_1 wwl5 wwl6 wwl7 wwl8_1 wwl9 wwl10 wwl11 wwl12_1 wlw1 wlw2 wlw3 wlw4_1 wlw5 wlw6 q207 wlw8_1 wlw9 wlw10 wlw11 wlw12_1 wll1 wll2 wll3 wll4_1 wll5 wll6 wll7 wll8_1 wll9 wll10 wll11 wll12_1 lww1 lww2 lww3 lww4_1 lww5 lww6 lww7 lww8_1 lww9 lww10 lww11 lww12_1 lwl1 lwl2 lwl3 lwl4_1 lwl5 lwl6 lwl7 lwl8_1 lwl9 lwl10 lwl11 lwl12_1 llw1 llw2 llw3 llw4_1 llw5 llw6 llw7 llw8_1 llw9 llw10 llw11 llw12_1 lll1 lll2 lll3 lll4_1 lll6 lll5 lll7 lll8_1 lll9 lll10 lll11 lll12_1 q25_1 q27 q28 q29_1 q29_2 q29_3 q29_4 q30_1 q31_1 q32 q33 q34 q35 q36 q37 q38 q38_text q39 q40 dobrfl_71 v180 starttime endtime timespent timespent_seconds timespent_minutes q17 q20 q23

order gender age trustparl_pre trustgov_pre trustpoli_pre trustparty_pre swd_pre willvoteref_pre leftright polintr issuesal_divorce issuesal_baincome issuesal_womenrole issuesal_votingage issuesal_directelect partyid partyid_party tv newspaper radionews socialmedia internetnews decision1 decision2 decision3 group accept1 accept2 accept3 alarmed hopeful angry frustrated proud excited happy outraged frustration satisref fair_process moral_expect influence_dec state_opinion pros reasonunfair reasonfair trustparl_post trustgov_post trustpoli_post trustparty_post swd_post willvoteref_post changeprocedure reasonschangeprocedure MC1 MC2 edu class1 class2 comments 

save "2_clean_data.dta"
